package com.joysuch.wwyt.common.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.joysuch.wwyt.common.entity.CommonImportTemplate;
import com.joysuch.wwyt.common.service.CommonImportTemplateService;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author heqifeng
 * @since 2022-01-07
 */
@Controller
@RequestMapping("/common/common-import-template")
public class CommonImportTemplateController {

    @Autowired
    private CommonImportTemplateService service;

    @ResponseBody
    @GetMapping("pageTemplate")
    public ResultBean pageTemplate(Integer pageNumber,Integer pageSize,String templateName) {
        IPage<CommonImportTemplate> page = service.pageTemplate(pageNumber, pageSize, templateName);
        return ResultBean.pageData(page.getRecords(),page.getTotal());
    }

    @GetMapping("downloadTemplate/{id}")
    @RequiresPermissions("template-download-center:download")
    public void downloadTemplateById(HttpServletRequest request, HttpServletResponse response,@PathVariable Long id) {
        service.downLoadTemplate(request,response,id);
    }


    @PostMapping("downloadTemplate")
    @RequiresPermissions("template-download-center:batch-export")
    public void downloadTemplateBatch(HttpServletRequest request, HttpServletResponse response,@RequestBody List<Long> ids) throws IOException {
        service.downLoadTemplateBatch(request,response,ids);
    }

    @PostMapping("checkDownloadTemplate")
    @ResponseBody
    public ResultBean checkDownloadTemplate(@RequestBody List<Long> ids) {
        service.checkDownloadTemplate(ids);
        return ResultBean.defaultSuccessResult();
    }

}

